package com.nb.hdj.testCase.audioandvideoModule;

import com.nb.hdj.data.HtAudioAndVideoEnum;
import com.nb.hdj.model.MultimediaManagement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * @Description: TODO
 * @Author: hedongjia
 * @Date: 2021/12/27 下午6:50
 * @Version: v1.0
 */
public class ViewMultimediaCase extends AudioAndVideoCaseBase{
    //发布频道名称
    private String channelName="";
    /**
     * 查看课程名称
     * @param driver
     * @return
     */
    public boolean viewMultimedia(WebDriver driver){
        try {
            //点击音视频管理
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.MENU.getValue()));
            //点击多媒体课程
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.MULTIMEDIA_COURSE_MENU.getValue()));
            //判断第一行元素是否为空
            seleniumUtil.sleep(1000);
            //String elementText = seleniumUtil.getElementText(driver, By.xpath(HtAudioAndVideoEnum.First_Name.getValue()));
            if(!seleniumUtil.elementTextIsEqual(driver,By.xpath(HtAudioAndVideoEnum.First_Name.getValue()),"")){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 新增课程名称
     * @param driver
     * @param mm
     * @return
     */
    public boolean insertMultimedia(WebDriver driver, MultimediaManagement mm){
        try {
            //点击新增课程
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.COURSE_INSERT_BUTTON.getValue()));
            //上传课程封面
            seleniumUtil.elementSendKeys(driver,By.xpath(HtAudioAndVideoEnum.COURSE_COVER_UPLOAD.getValue()),mm.getCourseCoverAddress());
            //输入课程名称
            seleniumUtil.elementClickAndClearAndInput(driver, By.xpath(HtAudioAndVideoEnum.COURSE_NAME.getValue()),mm.getCourseName());
            //输入课程简介
            seleniumUtil.elementClickAndClearAndInput(driver, By.xpath(HtAudioAndVideoEnum.COURSE_INTRODUCE.getValue()),mm.getCourseIntroduce());
            //富文本输入操作
            seleniumUtil.richTextInput(driver,mm.getCourseContent());
            //输入备注
            seleniumUtil.elementClickAndClearAndInput(driver, By.xpath(HtAudioAndVideoEnum.NOTE.getValue()),mm.getCourseIntroduce());
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.CONFIRM_BUTTON.getValue()));
            seleniumUtil.sleep(1000);
            if(seleniumUtil.elementTextIsEqual(driver,By.xpath(HtAudioAndVideoEnum.First_Name.getValue()),mm.getCourseName())){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 设置发布频道
     * @param driver
     * @return
     */
    public boolean publishChannel(WebDriver driver,MultimediaManagement mm){
        try {
            //点击第一行课程选择框
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.First_Name_Select.getValue()));
            //点击设置发布频道
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Set_Publish_Channel.getValue()));
            //点击选择发布频道
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Select_Publish_Channel.getValue()));
            //获取到频道名称
            seleniumUtil.sleep(500);
            channelName=seleniumUtil.getElementText(driver,By.xpath(HtAudioAndVideoEnum.Select_First_Channel.getValue()));
            //选择第一个频道
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Select_First_Channel.getValue()));
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Publish_CONFIRM_BUTTON.getValue()));
            seleniumUtil.sleep(1000);
            //跳转至发布的频道tab
            seleniumUtil.elementClick(driver, By.xpath("//*[@class='el-tabs__item'][text()='"+channelName+"']"));
            if(seleniumUtil.elementTextIsEqual(driver,By.xpath(HtAudioAndVideoEnum.First_Name.getValue()),mm.getCourseName())){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 撤销发布
     * @param driver
     * @return
     */
    public boolean cancelPublishChannel(WebDriver driver,MultimediaManagement mm) {
        try {
            //点击第一行课程选择框
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.First_Name_Select.getValue()));
            //点击撤销发布按钮
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Cancel_Publish_Channel.getValue()));
            //撤销点击确定
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Cancel_Channel_Confirm.getValue()));
            //跳转至发布的频道tab
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Course_Library.getValue()));
            if(seleniumUtil.elementTextIsEqual(driver,By.xpath(HtAudioAndVideoEnum.First_Name.getValue()),mm.getCourseName())){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 删除课程
     * @param driver
     * @return
     */
    public boolean deleteCourse(WebDriver driver,MultimediaManagement mm) {
        try {
            //点击第一行课程选择框
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.First_Name_Select.getValue()));
            //点击删除
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Delete_Course.getValue()));
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(HtAudioAndVideoEnum.Cancel_Channel_Confirm.getValue()));
            seleniumUtil.sleep(1000);
            if(!seleniumUtil.elementTextIsEqual(driver,By.xpath(HtAudioAndVideoEnum.First_Name.getValue()),mm.getCourseName())){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }
}
